package com.yq.design.proxy;

import com.yq.design.proxy.dynamicProxy.CglibFactory;
import com.yq.design.proxy.dynamicProxy.DynamicProxyFactory;
import com.yq.design.proxy.staticProxy.StaticProxyFactory;

/**
 * @ClassName Client
 * @Description 代理
 * @Author yaoqiang
 * @Date 2021/2/24 10:08
 * @Version 1.0
 */
public class Client {
    public static void main(String[] args) {

        testStaticProxy();
        testDynamicProxy();
        testCglib();
    }

    /**
     * 静态代理
     */
    public static void testStaticProxy() {
        TeacherDao teacherDao = new TeacherDao();
        StaticProxyFactory teachProxy = new StaticProxyFactory(teacherDao);
        teachProxy.teach();
    }

    public static void testDynamicProxy() {
        ITeacherDao iTeacherDao = new TeacherDao();
        ITeacherDao proxyInstance = (ITeacherDao)new DynamicProxyFactory(iTeacherDao).getProxyInstance();
        System.out.println("proxyInstance="+proxyInstance.getClass());
        proxyInstance.teach();
    }
    public  static  void testCglib(){
        Teacher teacher = new Teacher();
        Teacher proxyInstance = (Teacher)new CglibFactory(teacher).getProxyInstance();
        proxyInstance.teach();
    }

}
